package com.lagou.controller;

import com.lagou.dao.TArticleMapper;
import com.lagou.po.TArticle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Calendar;

@Controller
public class LoginController {

    @Autowired
    private RedisTemplate<Object, Object> redisTemplate;
    @Autowired
    private TArticleMapper tArticleMapper;

    @RequestMapping("/toLoginPage")
    public String toLoginPage(Model model){
        model.addAttribute("currentYear", Calendar.getInstance().get(Calendar.YEAR));
        TArticle article = tArticleMapper.selectByPrimaryKey(1);
        model.addAttribute("mysqlString", article.getTitle()+","+article.getContent());
        System.out.println(redisTemplate.opsForValue().get("test1"));
        redisTemplate.opsForValue().set("test1","1111111111");
        Object test1 = redisTemplate.opsForValue().get("test1");
        model.addAttribute("redisString", test1.toString());
        System.out.println(redisTemplate.opsForValue().get("test2"));
        redisTemplate.opsForSet().add("test3",111);
        redisTemplate.opsForSet().add("test3",222);
        redisTemplate.opsForSet().add("test3",333);
        System.out.println(redisTemplate.opsForSet().pop("test3"));
        System.out.println(redisTemplate.opsForSet().pop("test3"));
//        System.out.println(redisTemplate.opsForSet().pop("test3"));
        return "login";
    }



}
